package com.lottery.ruok.lottrey.dialog;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.retrofitModule.response.GetPayListResponse;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ASUS on 2017/8/2.
 */

public class ChoosePayTypeDialog extends DialogFragment {
    @BindView(R.id.listView)
    ListView listView;

    private ArrayList<GetPayListResponse> payTypeBeanArrayList;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //自定义对话框样式
        View v = inflater.inflate(R.layout.choose_pay_dialog_layout, null);

        ButterKnife.bind(this, v);

//        payTypeBeanArrayList = getArguments().getParcelableArrayList("types");

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
//                Intent intent = new Intent(getActivity(), AutoChargeActivity.class);
//                intent.putExtra("title", payTypeBeanArrayList.get(i).getName());
//                intent.putExtra("amount", getArguments().getFloat("amount"));
//                intent.putExtra("names_alias", getArguments().getString("names_alias"));
//                intent.putExtra("payType", payTypeBeanArrayList.get(i).getId());
//                startActivity(intent);
            }
        });

        MyAdapter myAdapter = new MyAdapter();
        listView.setAdapter(myAdapter);

        return v;
    }

    class MyAdapter extends BaseAdapter {
        @Override
        public int getCount() {
            return  payTypeBeanArrayList.size();
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolder holder;
            if (view != null) {
                holder = (ViewHolder) view.getTag();
            } else {
                view = LayoutInflater.from(getContext()).inflate(R.layout.charge_type_item, null);
                holder = new ViewHolder(view);
                view.setTag(holder);
            }

            holder.type.setText(payTypeBeanArrayList.get(i).getNames());

            return view;
        }

        class ViewHolder {
            @BindView(R.id.type)
            TextView type;

            ViewHolder(View view) {
                ButterKnife.bind(this, view);
            }
        }
    }
}
